# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: check_equip_comm_thread.py
  @time: 2022/7/31 17:04
  @desc:
"""
from PyQt5.QtCore import QObject, pyqtSignal, QThread
import time
from ATS.proberdriver.cascade_prober import CascadeProber
from utils.log_util import loggings


class InitProbeTask(QObject):
    result_signal = pyqtSignal(object, object, object)
    error_signal = pyqtSignal(object)
    finish_signal = pyqtSignal()

    def __init__(self, probe_address):
        super().__init__()
        self.cp = CascadeProber(probe_address)

    def run(self):
        try:
            self.subdie_lable_list = []
            self.wafer_die_count = int(self.cp.get_wafer_info().DiesCount)
            result = self.cp.read_map_position()
            for i in range(result.LastSiteIndex):
                if self.cp.get_subdie_status(i) == "E":
                    subdie_label = self.cp.get_subdie_label(i)
                    if subdie_label:
                        self.subdie_lable_list.append(subdie_label)
            self.result_signal.emit(self.cp, self.wafer_die_count, self.subdie_lable_list)
        except Exception as e:
            loggings.error(f"InitProbeTask,{e}")
            self.error_signal.emit(str(e))
        finally:
            self.finish_signal.emit()
